/**
* @package Scribble
*/
$(document).ready(function() {

	// Make dash widgets sortable
	$('#dashboard-widgets').sortable({
		axis: 'y',
		cursor: 'move',
		handle: 'h3 strong',
		update: function() {
			// TODO: Store positions in cookie or server-side somewhere?
		}
	});

	// Add handlers to the "toggle" links on all dash widgets
	$('.dashwidget h3 a').click(function() {
		var li = $(this).parents('li');
		var body = li.children('div.dashwidget-body');
		if(li.hasClass('dashwidget-closed')) {
			body.slideDown().parent('li').removeClass('dashwidget-closed');
		}
		else {
			body.slideUp().parent('li').addClass('dashwidget-closed');
		}

		// TODO: Store state in cookie or server-side?

		// Prevent bubbling
		this.blur();
		return false;
	});
});